package serializacja;

import model.Worker;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Author: Daniel
 * Date: 08.08.13
 */

public class OdczytIZapisDoPliku {
    public static final String FILE_NAME = "pracownicy.dat";

    public void zapiszDoPliku(List<Worker> pracownicy) throws IOException {
        FileOutputStream fos = new FileOutputStream(FILE_NAME);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(pracownicy);
        oos.close();
        fos.close();
    }

    public List<Worker> odczytajPracownikowZPliku() throws IOException, ClassNotFoundException {
        FileInputStream fis = new FileInputStream(FILE_NAME);
        ObjectInputStream ois = new ObjectInputStream(fis);
        Object readObject = ois.readObject();
        if (readObject instanceof List)
            return (List) readObject;
        else
            return new ArrayList<Worker>();
    }
}
